import Vue from "vue";
import Router from "vue-router";
import approvalsRouter from "./modules/approvals";
import departmentsRouter from "./modules/departments";
import employeesRouter from "./modules/employees";
import permissionRouter from "./modules/permission";
import attendancesRouter from "./modules/attendances";
import salarysRouter from "./modules/salarys";
import settingRouter from "./modules/setting";
import socialRouter from "./modules/social";
import userRouter from "./modules/user";
Vue.use(Router);
/* Layout */
import Layout from "@/layout";
//静态路由
export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true,
  },

  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true,
  },

  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        name: "dashboard",
        component: () => import("@/views/dashboard/index"),
        meta: { title: "首页", icon: "dashboard" },
      },
    ],
  },

  //公共导入的路由组件
  {
    path: "/import",
    component: Layout,
    hidden: true, //隐藏在左侧菜单中
    children: [
      {
        path: "",
        component: () => import("@/views/import"),
      },
    ],
  },
  userRouter,
];
//动态路由
//这里导出这个变量，后面做权限的时候会用到
export const asyncRoutes = [
  approvalsRouter,
  departmentsRouter,
  employeesRouter,
  permissionRouter,
  attendancesRouter,
  salarysRouter,
  settingRouter,
  socialRouter,
];
const createRouter = () =>
  new Router({
    mode: "history", // require service support
    base: "hr/", //固定的默认访问地址
    scrollBehavior: () => ({ y: 0 }),
    // routes: [...constantRoutes, ...asyncRoutes], //静态路由和动态路由合并
    routes: [...constantRoutes], //静态路由
  });

const router = createRouter(); //实例化一个路由

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  //重置路由
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router 这个matcher就是路由表的数据
}

export default router;
